//
//  ExpertViewController.m
//  ProjectA_ManualGuest
//
//  Created by dingcong on 16/6/14.
//  Copyright © 2016年 丁聪. All rights reserved.
//

#import "ExpertViewController.h"
#import "CellForThreePIC.h"
#import "ExpertModel.h"
#import "NetWorkingHandle.h"
#import "LoginOfVC.h"
#import "ImageTextResponse.h"
#import "FlowlayoutOfImageText.h"
#import "RootVCOfPicText.h"
@interface ExpertViewController ()

@property(nonatomic, retain)NSMutableArray *mArrOfData;

@end

@implementation ExpertViewController



- (void)dealloc
{
    
    [_mArrOfData release];
    
    
    [super dealloc];
    
    
    
    
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    
    [self.tableView registerClass:[CellForThreePIC class] forCellReuseIdentifier:@"expert"];
    [self GetData];
}


- (void)GetData
{
    
    NSString *url = @"http://m.shougongke.com/index.php?&c=Index&a=daren";
    
    NetWorkingHandle *net = [[NetWorkingHandle alloc]init];
    
    [net netWorkingHandlePostURL:url httpBody:nil completion:^(id result, NSData *data, NSURLResponse *response, NSError *error) {
        self.mArrOfData = [NSMutableArray array];
        
        
        NSArray *arr = [result objectForKey:@"data"];
        
        
        
        for (NSDictionary *dic in arr)
        {
            
            ExpertModel *model = [[ExpertModel alloc]init];
            [model setValuesForKeysWithDictionary:dic];
            [self.mArrOfData addObject:model];
            
//            for (NSDictionary *diction in model.list)
//            {
//                ExpertModel *model2 = [[ExpertModel alloc]init];
//                [model2 setValuesForKeysWithDictionary:diction];
//                [self.mArrOfList addObject:model2];
//                NSLog(@"%ld", self.mArrOfList.count);
//                [model2 release];
//            }
            
            [model release];
            
        }
        
        
        
         
        

        
        
        [self.tableView reloadData];
    }];
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    
    
    
    return self.mArrOfData.count;
    
    
}


- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    
    
    return 190;
    
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    CellForThreePIC *cell = [tableView dequeueReusableCellWithIdentifier:@"expert"];
    cell.model = self.mArrOfData[indexPath.row];
    [cell.button addTarget:self action:@selector(push:) forControlEvents:UIControlEventTouchUpInside];
    cell.selectionStyle = UITableViewCellSeparatorStyleNone;
    return cell;
    
    
    
    
}

- (void)push:(UIButton *)push{
    
    LoginOfVC *vc = [[LoginOfVC alloc]init];
    [self presentViewController:vc animated:YES completion:^{
        
    }];
    
    
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    
    ExpertModel *model = self.mArrOfData[indexPath.row];
    
    
    FlowlayoutOfImageText *layout = [[FlowlayoutOfImageText alloc]init];
    ImageTextResponse *response = [[ImageTextResponse alloc]initWithCollectionViewLayout:layout];
    
    response.strOfhandId = [[model.list objectAtIndex:0]objectForKey:@"hand_id"]  ;
    NSLog(@"%@", response.strOfhandId);
    layout.itemSize = CGSizeMake(SCREEN_WIDTH, CGRectGetHeight(response.view.bounds));
    layout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
    layout.minimumInteritemSpacing = 0;
    layout.minimumLineSpacing = 0;
    layout.sectionInset = UIEdgeInsetsMake(0, 0, 0, 0);
    response.collectionView.pagingEnabled = YES;
    [self presentViewController:response animated:YES completion:^{
        
    }];
    
    [layout release];
    [response release];
    
    
}

@end
